
import { sys, native } from 'cc';
import { BCGameLog } from '../../utils/BCGameLog';
import { BCProjectDefines } from '../../utils/BCProjectDefines';
import { BCPlatformInterface } from './BCPlatformInterface';
import { JSB } from 'cc/env';
import { BCNotificationCenter } from '../BCNotificationCenter';

/**
 * Predefined variables
 * Name = BCAndroidMgr
 * DateTime = Fri Dec 31 2021 18:09:34 GMT+0800 (中国标准时间)
 * Author = 风流鼻涕淌
 * FileBasename = BCAndroidMgr.ts
 * FileBasenameNoExtension = AndroidMgr
 * URL = db://assets/Main/script/Controller/platform/BCAndroidMgr.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */

const PACKET_NAME: string = "com.okey.game.bridge.";

const callPlatform = (className: string, funcName: string, params: string, ...args: any) => {
	let result = null;
	if (JSB) {
		if (sys.os == sys.OS.ANDROID) {
			BCGameLog.log(PACKET_NAME + className, funcName);
			try {
				result = native.reflection.callStaticMethod(PACKET_NAME + className, funcName, params, ...args);
			} catch (e) {
				
			}
		}
	}
	return result;
};

export class BCAndroidMgr extends BCPlatformInterface {
	setScreenOrientation(orientation: BCProjectDefines.ScreenOrientation) {
		throw new Error('Method not implemented.');
	}
	getDeviceId(): string {
		throw new Error('Method not implemented.');
	}
	getAppVersion(): string {
		throw new Error('Method not implemented.');
	}
	showToast(toast: string) {
		throw new Error('Method not implemented.');
	}
	copy(text: string) {
		throw new Error('Method not implemented.');
	}
	sendEvent(eventName: string, params?: Map<string, any>) {
		throw new Error('Method not implemented.');
	}
	vibrate(duration: number) {
		throw new Error('Method not implemented.');
	}
}

class androidBridge {
	private static m_instance: androidBridge = null;

	private constructor(){}

	static get inatance() {
		if (!this.m_instance) this.m_instance = new androidBridge();
		return this.m_instance;
	}

	notifyNetworkStatusChange(status: boolean){
		BCNotificationCenter.instance.emitEvent(BCProjectDefines.NoticeKey.DeviceNetChange, status);
	}
}

window["App2Game"] = androidBridge.inatance;